home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!insosf1.netins.net
- From: Alan Jones <alan.jones@qcs.org>
- Newsgroups: comp.sys.cbm
- Subject: Commodore Arithmetic
- Date: Wed, 7 Feb 1996 11:43:00 GMT
- Organization: Quad-cities Computer Society
- Message-ID: <96020719151143766@qcs.org>
- X-NNTP-Posting-Host: insosf1.netins.net
- X-Mail2News-Path: insosf1.netins.net
-
-
- Recently, the C64/128 floating point arithmetic has been maligned
- here. The C64/128 has good floating point math. It uses 5 byte reals
- with a 4 byte (32 bit) mantissa. There are no bugs in the basic FP
- arithmetic. The reals ARE limited in range and precision. They are
- more useful than compters using 32 bit reals, but not up to IEEE
- standard arithmetic. IEEE FP arithmetic (double and extended
- precision...) would be much slower than our existing FP routines. Of
- course it might be possible to interface a hardware FPU to the new
- Super64/128CPU (65816).
-
- The other C64/128 FP routines, such as SIN, EXP, and functions that use
- them are not accurate to full 32 bit FP precision. When used with
- care, they are often accurate enough for engineering work.
-
- The most annoying inaccuracy may be the conversion between binary FP
- and decimal for I/O. BASIC only prints 9 decimal digits of a FP
- number, but our binary FP number has about 9.6 decimal digits of
- precision. What you see is not what you have! Of course there are
- some simple tricks that you can use to print the FP number with more
- decimal precision, and you could do I/O using HEX notation. If you
- save intermediate results for later use, make sure you write the FP
- values as binary rather than ASCII (converted to decimal).
-
- If you do accounting type stuff with dollars and cents, using binary FP
- with its limited precision and rounding can be anoying. If your
- results are off one penny, all of your work will be suspect. Our 6502
- family of CPUs also has decimal arithmetic. It can do decimal
- arithmetic exactly, although you may have to program it yourself. I
- think the Paperclip word Processor will do simple calculations with up
- to 40 decimal digits of precision.
-
- If you are using 64+ bit FP you can compute some things in a fast and
- sloppy manner. Some programs that work OK on an IBM PC or workstation
- need more careful attention when coded for a C64/128.
-
- Some numbers can not be represented exactly in binary FP formats of any
- precision. If you want to calculate:
-
- a:=(1/3)*(1/5)*(1/7)*(1/11)
-
- You should code it as:
-
- a:=1/(3*5*7*11)
-
- Asside from being faster, it is more accurate.
-
- There are many tips for preserving numerical accuracy in computations.
- There are often interesting tradoffs between computation speed, memory
- usage, and accuracy and stability. There are even some C64/128
- specific tips. (e.g. we usually store a real value in 5 bytes of
- memory but push it onto a stack as 6 bytes when we want to use it.)
-
- This is not intended to be a Commodore FP tutorial. It is reminder
- that the C64/128 can be used for "heavy math", and there are no bugs
- in the Commodore +, -, *, /, Floating Point arithmetic routines. It
- uses 32 binary bit mantisa FP reals with proper rounding.
- Simple examples can always be contrived to demonstrate a perceived FP
- bug by computer illiterates(?).
-
- alan.jones@qcs.org
-
- ___ QWKRR128 V4.32 [R]
-